@extends('layouts.back_stage')
@section('content')
    <link href="{{env('CDN_DOMAIN_NAME')}}/store/commoncss/simplePagination.css" rel="stylesheet">
    <link rel="stylesheet" href="{{env('CDN_DOMAIN_NAME')}}/css/commoncss/just-tip.css">
    <script src="{{env('CDN_DOMAIN_NAME')}}/js/commonjs/justTools.js"></script>
    <div class="container">
        <div style="padding:20px 0;margin-bottom:30px;">
            <h3 style="float:left;">退货品牌列表</h3>
            <form action="/warehouse/export-inventory" method="get" style="float:right;">
                <input type="hidden" name="id" value="{{$inventory_id}}">
                <button type="submit" class="btn btn-info">导出</button>
            </form>
        </div>
        <table class="table table-hover">
            <thead>
            <tr>
                <th>品牌</th>
                <th>年份</th>
                <th>店长盘点数</th>
                <th>仓库盘点数</th>
                <th>完成时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
        <div id="paging1" class="page" style=""></div>
        @if($unfinished==0 && $infos->is_check==0)
            <button style="float:right;margin-top:50px;" type="button" class="btn btn-info overAllBrand" onclick="overAllBrand()">完成</button>
            <input type="text" class="form-control remark" placeholder="备注" style="width:50%;float:right;margin-right:50px;margin-top:50px;">
        @elseif($unfinished==0 && $infos->is_check==1)
            <input type="text" class="form-control remark" disabled value="{{$remark}}" style="width:50%;float:right;margin-right:50px;margin-top:50px;">
        @endif
    </div>

    <script src="{{ env('CDN_DOMAIN_NAME') }}/store/commonjs/jquery.simplePagination.js?v0.0.3"></script>
    <script>
        $(".overAllBrand").mouseover(function(event){
            var _this = $(this);
            _this.justToolsTip({
                events:event,
                animation:"moveInLeft",
                //width:"300px",
                contents:"所有品牌均核对完成，再点击此按钮，提交财务",
                gravity:'left'
            });
        });
        /*搜索*/
        function souSan(){
            skip=1;
            pervNextSerach();
        };
        /*清空*/
        function reSetScan(){
            skip=1;
            $('.form-control').val("");
            $('.address').val("");
            pervNextSerach();
        };
        /*点击分页*/
        $(document).on('click','.page-link',function(){
            if($(this).attr('class') === "page-link next nextPage"){
                if($(this).parent().attr('class') == 'active'){
                    return false;
                }else{
                    skip=Number(skip)+1;
                    pervNextSerach();
                }
            }else if($(this).attr('class') === "page-link prev prevPage"){
                if($(this).parent().attr('class') == 'active'){
                    return false;
                }else{
                    skip=Number(skip)-1;
                    pervNextSerach();
                }
            }else if($(this).attr('class') === "page-link tcdNumber"){
                skip=Number($(this).text());
                pervNextSerach();
            }
        });
        /*页面初始化*/
        var skip = 1;
        pervNextSerach();
        function pervNextSerach(){
            var shop_id = '{{$shop_id}}';
            var id='{{$inventory_id}}';
            $.ajax({
                url:'/warehouse/return-sub-infos',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                type:'post',
                dataType:'json',
                data:{
                    skip:skip,
                    shop_id:shop_id,
                    id:id
                },
                success:function(data){
                    //console.log(data);
                    if(data.result.success){
                        $('.table tbody').empty();
                        var res=data.content.cont;
                        if(res.length>0){
                            for(var i in res){
                                var str='<tr>' +
                                    '<td>'+res[i].brand+'</td>' +
                                    '<td>'+res[i].year+'</td>' +
                                    '<td>'+res[i].count+'</td>' +
                                    '<td>'+res[i].scan_count+'</td>' +
                                    '<td>'+res[i].time+'</td>' +
                                    '<td>' +
                                    '<a href="/warehouse/inventory-return-order-check/'+res[i].id+'">详情</a>' +
                                    '</td>' +
                                    '</tr>';
                                $('.table tbody').append(str);
                            }
                        }else{
                            $('.table tbody').append("<tr><td class='text-center' colspan='6'>无数据</td></tr>");
                        }
                        $("#paging1").pagination({
                            items: data.content.total,
                            itemsOnPage: 10,
                            cssStyle: 'light-theme',
                            currentPage:data.content.skip
                        });
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.result.errorMsg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            });
        }
        /*完成*/
        function overAllBrand() {
            $(".oText").text("确定完成,提交财务吗？");
            $(".oMask").show();
            $(".oAnim").show();
            $(".oBtn0").attr('id','');
            $(".oBtn0").attr('id','overAllTrues');
        }
        /*点确定*/
        $(document).on('click','#overAllTrues',function(){
            $(".oMask").hide();
            $(".oAnim").hide();
            var id='{{$inventory_id}}';
            var remark=$(".remark").val();
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                type:'post',
                url:'/warehouse/inventory-return-complete',
                data:{
                    id:id,
                    remark:remark
                },
                dataType:'json',
                success:function (data) {
                    //console.log(data);
                    if(data.result.success){
                        $(".faceImg").attr("src","/img/laugh.png");
                        $(".oHandle").text("操作成功");
                        $(".oSuccess").show(0).delay(800).hide(0);
                        setTimeout(function () {
                            window.location.href='/warehouse/inventory-return-shop-details/'+data.content;
                        },800)
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.result.errorMsg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            });
        });
    </script>
@endsection




